//
//  RegisterEngine.m
//  HuLaQuan
//
//  Created by liyan on 16/1/14.
//  Copyright © 2016年 yuwubao. All rights reserved.
//

#import "RegisterEngine.h"

@implementation RegisterEngine

/*- (void)getSMSWithMobile:(NSString *)phone
{
    
    self.userPhone = phone;
    NSString *randomKey = [self createKeyWithLength:24];
    
    NSString *src = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?><msg service=\"getSmsCode\" sysName=\"attach\" sign=\"RSA\" serialNumber=\"1173837578615\" termId=\"star_open_esa\" termAdd=\"23.23,23.45\" termBrand=\"iPhone\" osVersion=\"iPhone OS 9.1\" appVersion=\"1.0.0\" tokenValue=\"\" userId=\"\" channelId=\"88888888\"><authMobile>%@</authMobile><callService>ZH_Us_userReg</callService><attach>attach</attach></msg>",phone];
    //
    NSLog(@"%@ -- src --- ",src);

    NSString *final = [NSString stringWithFormat:@"%@|%@|%@",[self firstString],[self secondStringWithKey:randomKey],[self thirdStringWithBody:src andKey:randomKey]];
    
    NSLog(@"%@",final);
    [YuHTTPClient XMLDataWithUrl:SERVER_HOST parameters:final success:^(BOOL isSuccess, id item){
        
        NSDictionary *result;
        if (isSuccess) {
            
        }else{
            NSLog(@"%@",item);
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:@"GetRegisterVeriCodeFinish" object:result];
    }];

}
- (void)verifySMSWithcode:(NSString *)code
{
    NSString *randomKey = [self createKeyWithLength:24];
    
    NSString *src = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?><msg service=\"authSmsCode\" sysName=\"attach\" sign=\"RSA\" serialNumber=\"1173837578615\" termId=\"star_open_esa\" termAdd=\"23.23,23.45\" termBrand=\"iPhone\" osVersion=\"iPhone OS 9.1\" appVersion=\"1.0.0\" tokenValue=\"\" userId=\"\" channelId=\"88888888\"><authMobile>%@</authMobile><smsCode>%@</smsCode><attach>attach</attach></msg>",self.userPhone,code];
    NSLog(@"%@ -- src --- ",src);
    
    NSString *final = [NSString stringWithFormat:@"%@|%@|%@",[self firstString],[self secondStringWithKey:randomKey],[self thirdStringWithBody:src andKey:randomKey]];
    
    NSLog(@"%@",final);
    [YuHTTPClient XMLDataWithUrl:SERVER_HOST parameters:final success:^(BOOL isSuccess, id item){
        
        NSDictionary *result;
        if (isSuccess) {
            
        }else{
            NSLog(@"%@",item);
        }
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"verifyRegisterVeriCodeFinish" object:result];
    }];
}*/
- (void)registeUserPhone:(NSString *)phone withUserPassword:(NSString *)password withToken:(NSString *)token
{
    NSString *randomKey = [self createKeyWithLength:24];
    
    //登录密码加密
    NSString *pw = [RSA encryptString:password publicKey:PUBLIC_KEY];
    
    NSString *src = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?><msg service=\"userReg\" sysName=\"attach\" sign=\"RSA\" serialNumber=\"%@\" termId=\"star_open_esa\" termAdd=\"23.23,23.45\" termBrand=\"iPhone\" osVersion=\"iPhone OS 9.1\" appVersion=\"1.0.0\" tokenValue=\"%@\" userId=\"\" channelId=\"88888888\"><loginName>%@</loginName><loginPwd>%@</loginPwd><attach>attach</attach></msg>",[self getSerialNumber],token,phone,pw];
    
    NSLog(@"%@ -- src --- ",src);
    
    NSString *final = [NSString stringWithFormat:@"%@|%@|%@",[self firstString],[self secondStringWithKey:randomKey],[self thirdStringWithBody:src andKey:randomKey]];
    
    NSLog(@"%@",final);
    [YuHTTPClient XMLDataWithUrl:SERVER_HOST_CUSTOMER parameters:final success:^(BOOL isSuccess, id item){
        
        NSDictionary *result;
        if (isSuccess) {
            result = @{@"isSuccess":@YES};
        }else{
            result = @{@"isSuccess":@NO,@"message":item};
            NSLog(@"%@",item);
        }
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"RegisterFinish" object:result];
    }];
}
@end
